import Vue from "vue";
import VueRouter from "vue-router";
//  一级路由
import index from "../views/Index/index.vue";
import login from "../views/login/index.vue";

// 二级路由
import home from "../views/Index/home.vue";
import basic from "../views/Index/basic.vue";
import user from "../views/Index/user.vue";
import monitor from "../views/Index/monitor.vue";
import report from "../views/Index/report.vue";
import backwater from "../views/Index/backwater.vue";
import odds from "../views/Index/odds.vue";
import room from "../views/Index/room.vue";
import agent from "../views/Index/agent.vue";
import agentstatement from "../views/Index/agentstatement.vue";
import other from "../views/Index/other/other.vue";

// 三级路由
import admin from "../views/Index/other/admin.vue";
import falseuser from "../views/Index/other/falseuser.vue";
import log from "../views/Index/other/log.vue";
import upperscore from "../views/Index/other/upperscore.vue";
import lowerscore from "../views/Index/other/lowerscore.vue";
import toprecord from "../views/Index/other/toprecord.vue";
import subrecord from "../views/Index/other/subrecord.vue";
import airship from "../views/Index/other/airship.vue";
import gambling from "../views/Index/other/gambling.vue";
import racing from "../views/Index/other/racing.vue";
import rapidly from "../views/Index/other/rapidly.vue";
import recording from "../views/Index/other/recording.vue";
import australia10 from "../views/Index/other/australia10.vue";
import australia5 from "../views/Index/other/australia5.vue";
import articleList from "../views/Index/other/articleList.vue";
import publisharticle from "../views/Index/other/publisharticle.vue";
import recharge from "../views/Index/other/recharge.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    component: index,
    children: [
      {
        path: "/index/home",
        component: home,
        meta: {
          requireLogin: true
        }
      },
      {
        path: "/index/basic",
        component: basic
      },
      {
        path: "/index/user",
        component: user
      },
      {
        path: "/index/monitor",
        component: monitor
      },
      {
        path: "/index/report",
        component: report
      },
      {
        path: "/index/backwater",
        component: backwater
      },
      {
        path: "/index/odds",
        component: odds
      },
      {
        path: "/index/room",
        component: room
      },
      {
        path: "/index/agent",
        component: agent
      },
      {
        path: "/index/agentstatement",
        component: agentstatement
      },
      {
        path: "/index/other",
        component: other,
        children: [
          {
            path: "/index/other/admin",
            component: admin
          },
          {
            path: "/index/other/falseuser",
            component: falseuser
          },
          {
            path: "/index/other/log",
            component: log
          },
          {
            path: "/index/other/upperscore",
            component: upperscore
          },
          {
            path: "/index/other/lowerscore",
            component: lowerscore
          },
          {
            path: "/index/other/toprecord",
            component: toprecord
          },
          {
            path: "/index/other/subrecord",
            component: subrecord
          },
          {
            path: "/index/other/aracing",
            component: racing
          },

          {
            path: "/index/other/airship",
            component: airship
          },
          {
            path: "/index/other/gambling",
            component: gambling
          },
          {
            path: "/index/other/rapidly",
            component: rapidly
          },
          {
            path: "/index/other/recording",
            component: recording
          },
          {
            path: "/index/other/australia10",
            component: australia10
          },
          {
            path: "/index/other/australia5",
            component: australia5
          },
          {
            path: "/index/other/articleList",
            component: articleList
          },
          {
            path: "/index/other/publisharticle",
            component: publisharticle
          },
          {
            path: "/index/other/recharge",
            component: recharge
          },
          {
            path: "/index/other",
            redirect: "/index/other/admin"
          }
          
        ]
      },
      {
        path: "",
        redirect: "index/home"
      }
    ]
  },
  {
    path: "/login",
    component: login
  },
  {
    path: "*",
    redirect: "/index/home"
  }
];

const router = new VueRouter({
  routes
});

router.beforeEach((to, from, next) => {
  // 1. 判断是不是登录页面
  // 是登录页面
  if (to.path === "/login") {
    window.sessionStorage.removeItem("token");
    next();
  } else {
    // 不是登录页面
    // 2. 判断 是否登录过
    let token = sessionStorage.getItem("token");
    token ? next() : next("/login");
  }
});

export default router;
